package dynamicprogramming;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/5 1:36
 * https://leetcode-cn.com/problems/combination-sum-iv/
 */
public class CombinationSum4 {

    /**
     * dp[j]表示装满容量为j的背包的方案个数
     * @param nums
     * @param target
     * @return
     */
    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int j = 0; j <= target; j++) {
            for (int i = 0; i < nums.length; i++) {
                if (j - nums[i] >= 0) {
                    dp[j] += dp[j - nums[i]];
                }
            }
        }
        return dp[target];
    }

    public static void main(String[] args) {

    }
}
